package com.kingyun.gpsinspection.purificationservice.common.bean;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * 分页封装类
 */
public class Page implements Serializable,Iterable<JSONObject> {


    /**
     * 当前页号
     */


    private int limit=1;


    /**
     * 每页的记录数
     */
    private int pageSize=10;


    /**
     * 分页的结果集
     */
    private List<JSONObject> rows= Lists.newArrayList();


    /**
     * 总条数
     */
    private Long total;


    /**
     * 分页偏移量
     */
    private int offset;


    /**
     * 过滤条件
     */
    private Map<String,Object> params;


    /**
     * 类型参数
     */
    private String search;


    public Page(){

    }

    public Page(int offset,int pageSize){
        this.offset = offset;
        this.pageSize = pageSize;
    }



    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
        if(pageSize < 0){
            this.pageSize = 10;
        }
    }

    public List<JSONObject> getRows() {
        return rows;
    }

    public void setRows(List<JSONObject> rows) {
        this.rows = rows;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
        if(limit < 1){
            this.limit = 1;
        }
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    /*public int getOffSet() {
        return (this.limit-1) * this.pageSize;
    }

    public void setOffSet(int offset) {
        this.offset = offset;
    }
*/

    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public Map<String, Object> getParams() {
        return params;
    }

    public void setParams(Map<String, Object> params) {
        this.params = params;
    }

    /**
     * Returns an iterator over elements of type {@code T}.
     *
     * @return an Iterator.
     */
    @Override
    public Iterator<JSONObject> iterator() {
        return rows.iterator();
    }

    public String getSearch() {
        return search;
    }

    public void setSearch(String search) {
        this.search = search;
    }
}
